import math

def is_prime(n):
    r = True
    if n % 2:  
        for i in range(3, int(math.sqrt(n)) + 1, 2): 
            if n % i == 0:  
                r = False  
                break  
    else:  
        r = False  
    return r

def main():
    N = input()
    s = 0
    for i in range(len(N)):
        if N[i] == ' ':
            s += 1
    if s != 2:
        print("Wrong input")
    else:
        p1 = N.find(' ')
        n1 = N[:p1]

        p2 = N.rfind(' ')
        n2 = N[p1 + 1:p2]

        n3 = N[p2 + 1:]
        c1 = -1
        c2 = -1
        c3 = -1
        if n1 == "zero":
            c1 = 0
        elif n1 == "one":
            c1 = 1
        elif n1 == "two":
            c1 = 2
        elif n1 == "three":
            c1 = 3
        elif n1 == "four":
            c1 = 4
        elif n1 == "five":
            c1 = 5
        elif n1 == "six":
            c1 = 6
        elif n1 == "seven":
            c1 = 7
        elif n1 == "eight":
            c1 = 8
        elif n1 == "nine":
            c1 = 9

        if n2 == "zero":
            c2 = 0
        elif n2 == "one":
            c2 = 1
        elif n2 == "two":
            c2 = 2
        elif n2 == "three":
            c2 = 3
        elif n2 == "four":
            c2 = 4
        elif n2 == "five":
            c2 = 5
        elif n2 == "six":
            c2 = 6
        elif n2 == "seven":
            c2 = 7
        elif n2 == "eight":
            c2 = 8
        elif n2 == "nine":
            c2 = 9

        if n3 == "zero":
            c3 = 0
        elif n3 == "one":
            c3 = 1
        elif n3 == "two":
            c3 = 2
        elif n3 == "three":
            c3 = 3
        elif n3 == "four":
            c3 = 4
        elif n3 == "five":
            c3 = 5
        elif n3 == "six":
            c3 = 6
        elif n3 == "seven":
            c3 = 7
        elif n3 == "eight":
            c3 = 8
        elif n3 == "nine":
            c3 = 9

        if c1 == -1 or c2 == -1 or c3 == -1:
            print("Wrong input")
        else:
            ch = c1 * 100 + c2 * 10 + c3
            s = 0
            s1 = 0
            for i in range(ch, 2, -1):
                if is_prime(i):
                    s = i
                    break
            for i in range(ch, 1000):
                if is_prime(i):
                    s1 = i
                    break
            if ch - s < s1 - ch:
                print(s)
            elif ch - s > s1 - ch:
                print(s1)
            elif ch == s:
                print(s)

if __name__ == "__main__":
    main()
